<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="field[@type = 'select' and parent::doctype]">
		<xsl:variable name="is_new" select="parent::doctype/@action = 'create'"/>
		<xsl:variable name="document_field" select="../../document[@doctype_name = current()/parent::doctype/@name]/field[@name = current()/@name]"/>
		<div class="field">
			<label class="title_label" for="{@name}">
				<xsl:value-of select="@title"/>
				<xsl:text>:&#160;</xsl:text>
				<xsl:if test="@is_important = 1">
					<span class="star">*</span>
				</xsl:if>
			</label>
			<xsl:choose>
				<xsl:when test="@drop_down_view = 1">
					<select name="{@name}">
						<xsl:for-each select="item">
							<option value="{@value}">
								<xsl:choose>
									<xsl:when test="../../../pass_info/vars/var[@name = current()/../@name] = @value">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:when>
									<xsl:when test="../../../pass_info/vars/var[@name = current()/../@name]" />
									<xsl:when test="$document_field/@value_key = @value">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:when>
									<xsl:when test="$is_new and @is_default = 1">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:when>
								</xsl:choose>
								<xsl:value-of select="@title"/>
							</option>
						</xsl:for-each>
					</select>
				</xsl:when>
				<xsl:otherwise>
					<div class="inline_labels">
						<xsl:for-each select="item">
							<input id="{../@name}_{@value}" class="radio-" type="radio" name="{../@name}" value="{@value}">
								<xsl:choose>
									<xsl:when test="../../../pass_info/vars/var[@name = current()/../@name] = @value">
										<xsl:attribute name="checked">checked</xsl:attribute>
									</xsl:when>
									<xsl:when test="../../../pass_info/vars/var[@name = current()/../@name]" />
									<xsl:when test="$document_field/@value_key = @value">
										<xsl:attribute name="checked">checked</xsl:attribute>
									</xsl:when>
									<xsl:when test="$is_new and @is_default = 1">
										<xsl:attribute name="checked">checked</xsl:attribute>
									</xsl:when>
								</xsl:choose>
							</input>
							<label for="{../@name}_{@value}">
								<xsl:value-of select="@title"/>
							</label>
						</xsl:for-each>
					</div>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:apply-templates mode="dtf_error" select="." />
			<xsl:if test="@comment != ''">
				<div class="comment-">
					<xsl:value-of select="@comment"/>
				</div>
			</xsl:if>
		</div>
	</xsl:template>
</xsl:stylesheet>
